﻿using System.Collections.Generic;
using System.Linq;
using SelfService.Model.Models;
using WalkingTec.Mvvm.Core;

namespace SelfService.ViewModel.SysTaskVMs
{
    public partial class SysTaskListVm : BasePagedListVM<SysTaskView, SysTaskSearcher>
    {

        protected override IEnumerable<IGridColumn<SysTaskView>> InitGridHeader()
        {
            return new List<GridColumn<SysTaskView>>{
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.ClassName),
                this.MakeGridHeader(x => x.TaskType),
                this.MakeGridHeader(x => x.LastRunTime),
                this.MakeGridHeader(x => x.LastEndTime),
                this.MakeGridHeader(x => x.NextRunTime),
                this.MakeGridHeader(x => x.TimeType),
                this.MakeGridHeader(x => x.LastRunResult),
                this.MakeGridHeader(x => x.CreateTime),
                this.MakeGridHeader(x => x.IsEnable),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysTaskView> GetSearchQuery()
        {
            var query = DC.Set<SysTask>()
                .Select(x => new SysTaskView
                {
				    ID = x.ID,
                    Name = x.Name,
                    ClassName = x.ClassName,
                    TaskType = x.TaskType,
                    LastRunTime = x.LastRunTime,
                    LastEndTime = x.LastEndTime,
                    NextRunTime = x.NextRunTime,
                    TimeType = x.TimeType,
                    LastRunResult = x.LastRunResult,
                    CreateTime = x.CreateTime,
                    IsEnable = x.IsEnable,
                })
                .OrderBy(x => x.CreateTime);
            return query;
        }

    }

    public class SysTaskView : SysTask{

    }
}
